﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using static System.Net.Mime.MediaTypeNames;

namespace Shopfloormanagement.CustomControls
{
    public partial class LineChart : UserControl
    {
        public LineChart()
        {
            InitializeComponent();
            chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
            chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
          
        }

        private int YMax = 60;

        [Category("自定义属性"), Description("Y轴最大值")]
        public int YaxisMaximum
        {
            get => YMax;
            set
            {
                YMax = value;
                chart1.ChartAreas[0].AxisY.Maximum = value;
            }
        }

        private int YMin = 0;

        [Category("自定义属性"), Description("Y轴最小值")]
        public int YaxisMinmum
        {
            get => YMin;
            set
            {
                YMin = value;
                chart1.ChartAreas[0].AxisY.Minimum = value;
            }
        }


        private double[] Xvalues = new double[31];

        [Category("自定义属性"), Description("X数值数组")]
        public double[] XaxisValues
        {
            get { return Xvalues; }
            set
            {
                Xvalues = value;
                for (int i = 0; i < XaxisValues.Length; i++)
                {
                    chart1.Series[0].Points[i].YValues[0] = Xvalues[i];
                    chart1.Invalidate();
                }
            }
        }

        private bool valueshownaslabel = false;

        [Category("自定义属性"), Description("显示数据标签")]
        public bool ValueShownAsLabel
        {
            get => valueshownaslabel;
            set
            {
                valueshownaslabel = value;
                chart1.Series[0].IsValueShownAsLabel = value;
            }
        }

        private Color valuelabelcolor = Color.Black;

        [Category("自定义属性"), Description("标签字体颜色")]
        public Color ValueLabelColor
        {
            get => valuelabelcolor;
            set
            {
                valuelabelcolor = value;
                chart1.Series[0].LabelForeColor = value;
            }
        }

        private Font valuelabelfont = new Font("Arial", 8);

        [Category("自定义属性"), Description("标签字体颜色")]
        public Font ValueLabelFont
        {
            get => valuelabelfont;
            set
            {
                valuelabelfont = value;
                chart1.Series[0].Font = value;
            }
        }

        private Color linecolor = Color.Blue;

        [Category("自定义属性"), Description("线条颜色")]
        public Color LineColor
        {
            get => linecolor;
            set
            {
                linecolor = value;
                chart1.Series[0].Color = value;
            }
        }

        private bool xmajorgrid = false;

        [Category("自定义属性"), Description("是否禁用X轴的网格线")]
        public bool XMajorGrid
        {
            get => xmajorgrid;
            set
            {
                xmajorgrid = value;
                chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = value;
            }
        }

        private bool ymajorgrid = false;

        [Category("自定义属性"), Description("是否禁用Y轴的网格线")]
        public bool YMajorGrid
        {
            get => ymajorgrid;
            set
            {
                ymajorgrid = value;
                chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = value;
            }
        }

        private string xaxislabeltext = "";

        [Category("自定义属性"), Description("X轴标签文本")]
        public string XaxisLabelText
        {
            get => xaxislabeltext;
            set
            {
                xaxislabeltext = value;
                chart1.ChartAreas[0].Axes[0].Title = value;
            }
        }

        private string yaxislabeltext = "";

        [Category("自定义属性"), Description("Y轴标签文本")]
        public string YaxisLabelText
        {
            get => yaxislabeltext;
            set
            {
                yaxislabeltext = value;
                chart1.ChartAreas[0].Axes[1].Title = value;
            }
        }

        private string seriestext = "";

        [Category("自定义属性"), Description("Series文本")]
        public string SeriesText
        {
            get => seriestext;
            set
            {
                seriestext = value;
                chart1.Series[0].LegendText = value;
            }
        }

        private bool seriestextvisible = false;

        [Category("自定义属性"), Description("是否显示Series文本")]
        public bool SeriesTextVisible
        {
            get => seriestextvisible;
            set
            {
                seriestextvisible = value;
                chart1.Series[0].IsVisibleInLegend = value;
            }
        }

        private Font axisxfont = new Font("Arial", 8);

        [Category("自定义属性"), Description("X轴标签字体")]
        public Font AxisXFont
        {
            get => axisxfont;
            set
            {
                axisxfont = value;
                chart1.ChartAreas[0].AxisX.LabelStyle.Font = value;
            }
        }

        private Font axisyfont = new Font("Arial", 8);

        [Category("自定义属性"), Description("Y轴标签字体")]
        public Font AxisYFont
        {
            get => axisyfont;
            set
            {
                axisyfont = value;
                chart1.ChartAreas[0].AxisY.LabelStyle.Font = value;
            }
        }


        private bool targetvisible = false;

        [Category("自定义属性"), Description("是否显示目标线")]
        public bool TargetVisible
        {
            get => targetvisible;
            set
            {
                targetvisible = value;
                chart1.Series[1].Enabled = value;
                chart1.Series[1].Color = Color.Red;

            }
        }

        private double targetvalue = 0;
        [Category("自定义属性"), Description("目标值")]

        public double TargetValue
        {
            get => targetvalue;
            set
            {
                targetvalue = value;
                chart1.Series[1].Points.AddXY(1, value);
                chart1.Series[1].Points.AddXY(31, value);
            }
        }

        private Color linecolor2 = Color.Blue;

        [Category("自定义属性"), Description("目标值线条颜色")]
        public Color LineColor2
        {
            get => linecolor2;
            set
            {
                linecolor2 = value;
                chart1.Series[1].Color = value;
            }
        }

        #region backups

        //private bool YType = false;
        //[DefaultValue(false), Description("自动设定Y轴最大值"), Category("自定义属性")]
        //public bool YaxisAuto
        //{
        //    get
        //    {
        //        return YType;
        //    }
        //    set
        //    {
        //        YType = value;
        //        if (YType == true)
        //        {
        //            chart1.ChartAreas[0].AxisY.Maximum = double.NaN;
        //        }
        //        else
        //        {
        //            chart1.ChartAreas[0].AxisY.Maximum = YMax;
        //        }
        //    }
        //}

        //#region 数值设置

        //private double X1value = 0;

        //[Category("自定义属性"), Description("X1数值")]
        //public double X01axisValue
        //{
        //    get => X1value;
        //    set
        //    {
        //        X1value = value;
        //        chart1.Series[0].Points[0].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X2value = 0;

        //[Category("自定义属性"), Description("X2数值")]
        //public double X02axisValue
        //{
        //    get => X2value;
        //    set
        //    {
        //        X2value = value;
        //        chart1.Series[0].Points[1].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X3value = 0;

        //[Category("自定义属性"), Description("X3数值")]
        //public double X03axisValue
        //{
        //    get => X3value;
        //    set
        //    {
        //        X3value = value;
        //        chart1.Series[0].Points[2].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X4value = 0;

        //[Category("自定义属性"), Description("X4数值")]
        //public double X04axisValue
        //{
        //    get => X4value;
        //    set
        //    {
        //        X4value = value;
        //        chart1.Series[0].Points[3].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X5value = 0;

        //[Category("自定义属性"), Description("X5数值")]
        //public double X05axisValue
        //{
        //    get => X5value;
        //    set
        //    {
        //        X5value = value;
        //        chart1.Series[0].Points[4].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X6value = 0;

        //[Category("自定义属性"), Description("X6数值")]
        //public double X06axisValue
        //{
        //    get => X6value;
        //    set
        //    {
        //        X6value = value;
        //        chart1.Series[0].Points[5].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X7value = 0;

        //[Category("自定义属性"), Description("X7数值")]
        //public double X07axisValue
        //{
        //    get => X7value;
        //    set
        //    {
        //        X7value = value;
        //        chart1.Series[0].Points[6].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X8value = 0;

        //[Category("自定义属性"), Description("X8数值")]
        //public double X08axisValue
        //{
        //    get => X8value;
        //    set
        //    {
        //        X8value = value;
        //        chart1.Series[0].Points[7].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X9value = 0;

        //[Category("自定义属性"), Description("X9数值")]
        //public double X09axisValue
        //{
        //    get => X9value;
        //    set
        //    {
        //        X9value = value;
        //        chart1.Series[0].Points[8].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X10value = 0;

        //[Category("自定义属性"), Description("X10数值")]
        //public double X10axisValue
        //{
        //    get => X10value;
        //    set
        //    {
        //        X10value = value;
        //        chart1.Series[0].Points[9].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X11value = 0;

        //[Category("自定义属性"), Description("X11数值")]
        //public double X11axisValue
        //{
        //    get => X11value;
        //    set
        //    {
        //        X11value = value;
        //        chart1.Series[0].Points[10].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X12value = 0;

        //[Category("自定义属性"), Description("X12数值")]
        //public double X12axisValue
        //{
        //    get => X12value;
        //    set
        //    {
        //        X12value = value;
        //        chart1.Series[0].Points[11].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X13value = 0;

        //[Category("自定义属性"), Description("X13数值")]
        //public double X13axisValue
        //{
        //    get => X13value;
        //    set
        //    {
        //        X13value = value;
        //        chart1.Series[0].Points[12].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X14value = 0;

        //[Category("自定义属性"), Description("X14数值")]
        //public double X14axisValue
        //{
        //    get => X14value;
        //    set
        //    {
        //        X14value = value;
        //        chart1.Series[0].Points[13].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X15value = 0;

        //[Category("自定义属性"), Description("X15数值")]
        //public double X15axisValue
        //{
        //    get => X15value;
        //    set
        //    {
        //        X15value = value;
        //        chart1.Series[0].Points[14].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X16value = 0;

        //[Category("自定义属性"), Description("X16数值")]
        //public double X16axisValue
        //{
        //    get => X16value;
        //    set
        //    {
        //        X16value = value;
        //        chart1.Series[0].Points[15].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X17value = 0;

        //[Category("自定义属性"), Description("X17数值")]
        //public double X17axisValue
        //{
        //    get => X17value;
        //    set
        //    {
        //        X17value = value;
        //        chart1.Series[0].Points[16].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X18value = 0;

        //[Category("自定义属性"), Description("X18数值")]
        //public double X18axisValue
        //{
        //    get => X18value;
        //    set
        //    {
        //        X18value = value;
        //        chart1.Series[0].Points[17].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X19value = 0;

        //[Category("自定义属性"), Description("X19数值")]
        //public double X19axisValue
        //{
        //    get => X19value;
        //    set
        //    {
        //        X19value = value;
        //        chart1.Series[0].Points[18].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X20value = 0;

        //[Category("自定义属性"), Description("X20数值")]
        //public double X20axisValue
        //{
        //    get => X20value;
        //    set
        //    {
        //        X20value = value;
        //        chart1.Series[0].Points[19].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X21value = 0;

        //[Category("自定义属性"), Description("X21数值")]
        //public double X21axisValue
        //{
        //    get => X21value;
        //    set
        //    {
        //        X21value = value;
        //        chart1.Series[0].Points[20].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X22value = 0;

        //[Category("自定义属性"), Description("X22数值")]
        //public double X22axisValue
        //{
        //    get => X22value;
        //    set
        //    {
        //        X22value = value;
        //        chart1.Series[0].Points[21].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X23value = 0;

        //[Category("自定义属性"), Description("X23数值")]
        //public double X23axisValue
        //{
        //    get => X23value;
        //    set
        //    {
        //        X23value = value;
        //        chart1.Series[0].Points[22].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X24value = 0;

        //[Category("自定义属性"), Description("X24数值")]
        //public double X24axisValue
        //{
        //    get => X24value;
        //    set
        //    {
        //        X24value = value;
        //        chart1.Series[0].Points[23].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X25value = 0;

        //[Category("自定义属性"), Description("X25数值")]
        //public double X25axisValue
        //{
        //    get => X25value;
        //    set
        //    {
        //        X25value = value;
        //        chart1.Series[0].Points[24].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X26value = 0;

        //[Category("自定义属性"), Description("X26数值")]
        //public double X26axisValue
        //{
        //    get => X26value;
        //    set
        //    {
        //        X26value = value;
        //        chart1.Series[0].Points[25].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X27value = 0;

        //[Category("自定义属性"), Description("X27数值")]
        //public double X27axisValue
        //{
        //    get => X27value;
        //    set
        //    {
        //        X27value = value;
        //        chart1.Series[0].Points[26].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X28value = 0;

        //[Category("自定义属性"), Description("X28数值")]
        //public double X28axisValue
        //{
        //    get => X28value;
        //    set
        //    {
        //        X28value = value;
        //        chart1.Series[0].Points[27].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X29value = 0;

        //[Category("自定义属性"), Description("X29数值")]
        //public double X29axisValue
        //{
        //    get => X29value;
        //    set
        //    {
        //        X29value = value;
        //        chart1.Series[0].Points[28].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X30value = 0;

        //[Category("自定义属性"), Description("X30数值")]
        //public double X30axisValue
        //{
        //    get => X30value;
        //    set
        //    {
        //        X30value = value;
        //        chart1.Series[0].Points[29].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //private double X31value = 0;

        //[Category("自定义属性"), Description("X31数值")]
        //public double X31axisValue
        //{
        //    get => X31value;
        //    set
        //    {
        //        X31value = value;
        //        chart1.Series[0].Points[30].YValues[0] = value;
        //        chart1.Invalidate();
        //    }
        //}

        //#endregion 数值设置

        #endregion backups
    }
}